package com.wc._16届国特冲刺营._05动态规划_状态压缩黑科技.星球;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/5/9 14:17
 * @description
 * https://www.lanqiao.cn/courses/51805/learning/?id=4072906&compatibility=false
 */
public class Main {
    /**
     * 思路：
     * 旅行商问题, 状压DP
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 20;
    static double INF = 1e10;
    static int[] x = new int[N], y = new int[N], z = new int[N], w = new int[N];
    // f[i][j] 表示状态为 i, 结尾为 j 的最短路
    static double[][] f = new double[1 << N][N];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 0; i < n; i++ ) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
            z[i] = sc.nextInt();
            w[i] = sc.nextInt();
        }

        for (int i = 0; i < 1 << n; i++) {
            Arrays.fill(f[i], INF);
        }

        for (int i = 0; i < n; i++) {
            f[1 << i][i] = 0;
        }
        for (int i = 0; i < 1 << n; i++) {
            // j -> k 走
            for (int j = 0; j < n; j++) {
                // 状态是否包含 j
                if ((i >> j & 1) == 0) continue;
                for (int k = 0; k < n; k++) {
                    // 状态是否包含 k
                    if ((i >> k & 1) == 1) continue;
                    // 将 k 加入状态
                    f[i | (1 << k)][k] = Math.min(f[i | (1 << k)][k], f[i][j] + dist(j, k));
                }
            }
        }
        double res = INF;
        for (int i = 0; i < n; i++) res = Math.min(res, f[(1 << n) - 1][i]);
        out.printf("%.2f\n", res);
        out.flush();
    }

    static double dist(int j, int k) {
        int x1 = x[j], y1 = y[j], z1 = z[j];
        int x2 = x[k], y2 = y[k], z2 = z[k];
        int x = x1 - x2, y = y1 - y2, z = z1 - z2;
        return Math.sqrt(x * x + y * y + z * z) * w[k];
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

